//
//  MNDRecordGroupViewController.m
//  PlusTenderDemo
//
//  Created by Vitas on 2018/7/17.
//  Copyright © 2018年 Bylongma. All rights reserved.
//

#import "MNDRecordGroupViewController.h"
#import "MNDPlusRecordContainerViewController.h"
#import "MNDInvestmentRecordViewController.h"
#import "MNDInvestRecordTenderDataModel.h"


@interface MNDRecordGroupViewController ()

@property (weak, nonatomic) IBOutlet UILabel *plusTenderNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *plusReturnMoneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *tenderNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *tenderReturnMoneyLabel;

@end

@implementation MNDRecordGroupViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
    // Do any additional setup after loading the view.
}

#pragma mark - 加载数据
- (void)loadData {
    
    kdeclare_weakself;
    [APIManager sendRequestWithURL:API_BORROW_RECORD_DATA parameters:[MNDSign signedParam] method:kXMHTTPMethodPOST onSuccess:^(ResponseModel *responseModel) {
        if (responseModel.status == ResponseSuccess) {
            MNDInvestRecordTenderDataModel *model = [MNDInvestRecordTenderDataModel mj_objectWithKeyValues:responseModel.data];
            [weakSelf configContentsWithModel:model];
            
        }else {
            [NetworkProgressHUD showHudMsg:responseModel.msg[@"error"]];
        }
    } onFailure:^(NSError *error) {
        [NetworkProgressHUD showHudNetworkError:error];
    }];
}

- (void)configContentsWithModel:(MNDInvestRecordTenderDataModel *)model {
    self.plusTenderNumLabel.text = [NSString stringWithFormat:@"%@个在投",model.tender_plan_num];
    if (model.wait_plan_return_money.floatValue > 0) {
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"今日回款总额%@元",model.wait_plan_return_money]];
        [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:250/255.0 green:101/255.0 blue:66/255.0 alpha:1.0] range:NSMakeRange(0, 6)];
        self.plusReturnMoneyLabel.attributedText = attStr;
    }else {
        self.plusReturnMoneyLabel.text = @"今日暂无回款";
    }
    self.tenderNumLabel.text = [NSString stringWithFormat:@"%@个在投",model.tender_num];
    if(model.wait_return_money.floatValue > 0){
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"今日回款总额%@元",model.wait_return_money]];
        [attStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:250/255.0 green:101/255.0 blue:66/255.0 alpha:1.0] range:NSMakeRange(0, 6)];
        self.tenderReturnMoneyLabel.attributedText = attStr;
    }else {
        self.tenderReturnMoneyLabel.text = @"今日暂无回款";
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row == 0) {
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MNDPlusRecordContainerViewController" bundle:nil];
        MNDPlusRecordContainerViewController *listlVC = [storyBoard instantiateViewControllerWithIdentifier:@"MNDPlusRecordContainerViewController"];
        [self.navigationController pushViewController:listlVC animated:YES];
    }else {
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"InvestmentRecord" bundle:nil];
        MNDInvestmentRecordViewController *recordVC = [storyBoard instantiateViewControllerWithIdentifier:@"MNDInvestmentRecordViewController"];
        [self.navigationController pushViewController:recordVC animated:YES];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
